import React, { Component } from 'react'
import axios from "axios"
export default class login extends Component {
    state={
        name:"",
        pwd:""
    }
    render() {
        let {name,pwd}=this.state
        return (
            <div>
                <input type="text" placeholder="亲输入用户名" value={name} name="name" onChange={this.handleChange.bind(this)}/>
                <input type="text" placeholder="亲输入密码" value={pwd} name="pwd" onChange={this.handleChange.bind(this)}/>
                <button onClick={this.handleClick.bind(this)}>登录</button>
            </div>
        )
    }
    handleChange(e){
        
    let tar=e.target.name
    console.log("跟多", tar);
        this.setState({
            [tar]:e.target.value
        })
    }
   async handleClick(){
       let {name,pwd}=this.state
        console.log("D点击");
        let res=await axios.get("/login",{params:{user:name,pwd:pwd}})
        console.log(res);
        if(res.data.code==0){
            //存储token
            window.localStorage.token=res.data.token
            this.props.history.push("/list")
        }
    }
}
